{% comment %}
<!--
  Copyright (C) 2008 ZHENG Zhong <http://www.zhengzhong.net/>

  Created on 2009-04-08.
  $Id$
-->
{% endcomment %}

<div id="ratings" class="ajax_box">

  <!-- main _____________________________________________________________________________________-->
  
  <div class="main">
  
    {% if resto.ratings %}
      <div>
        {% with resto.average as rating_as_value %}
        {% with resto.average_as_stars as rating_as_stars %}
          {% include "foodsnroses/include/rating.html" %}
        {% endwith %}
        {% endwith %}
        - based on {{resto.ratings}} ratings
        <span class="toggle_link">
          <a href="javascript:void(0);" onclick="$('#ratings .details').toggle('slow');">
            [details]
          </a>
        </span>
      </div>
      
      <div class="details hidden">
      
        <table>
          <tbody>
          
            <tr>
              <th colspan="2">
                <div class="details_head">Average rating:</div>
              </th>
            </tr>
            <tr>
              <th>Cuisine:</th>
              <td>
                {% with resto.cuisine as rating_as_value %}
                {% with resto.cuisine_as_stars as rating_as_stars %}
                  {% include "foodsnroses/include/rating.html" %}
                {% endwith %}
                {% endwith %}
              </td>
            </tr>
            <tr>
              <th>Economy:</th>
              <td>
                {% with resto.economy as rating_as_value %}
                {% with resto.economy_as_stars as rating_as_stars %}
                  {% include "foodsnroses/include/rating.html" %}
                {% endwith %}
                {% endwith %}
              </td>
            </tr>
            <tr>
              <th>Service:</th>
              <td>
                {% with resto.service as rating_as_value %}
                {% with resto.service_as_stars as rating_as_stars %}
                  {% include "foodsnroses/include/rating.html" %}
                {% endwith %}
                {% endwith %}
              </td>
            </tr>
            
            {% if rating %}
              <tr>
                <th colspan="2">
                  <div class="details_head">Your rating ({{rating.average|floatformat:2}} out of 5):</div>
                </th>
              </tr>
              <tr>
                <th>Cuisine:</th>
                <td>
                  {% with rating.cuisine as rating_as_value %}
                  {% with rating.cuisine_as_stars as rating_as_stars %}
                    {% include "foodsnroses/include/rating.html" %}
                  {% endwith %}
                  {% endwith %}
                </td>
              </tr>
              <tr>
                <th>Economy:</th>
                <td>
                  {% with rating.economy as rating_as_value %}
                  {% with rating.economy_as_stars as rating_as_stars %}
                    {% include "foodsnroses/include/rating.html" %}
                  {% endwith %}
                  {% endwith %}
                </td>
              </tr>
              <tr>
                <th>Service:</th>
                <td>
                  {% with rating.service as rating_as_value %}
                  {% with rating.service_as_stars as rating_as_stars %}
                    {% include "foodsnroses/include/rating.html" %}
                  {% endwith %}
                  {% endwith %}
                </td>
              </tr>
            {% endif %}{# rating #}
          
          </tbody>
        </table>
      
      </div><!--/.details-->
    
    {% else %}
      <span class="na">Nobody has rated this resto.</span>
    {% endif %}
  
  </div><!--/.main-->
  
  {% include "foodsnroses/ajax/ajax_error.html" %}
  
  <!-- view _____________________________________________________________________________________-->
  
  {% if not rating %}
  
    <div class="view">
      <div class="toggle_button">
        {% if user_ %}
          <a href="javascript:void(0);" onclick="toggleBox('#ratings');">Rate this resto!</a>
        {% else %}
          <a href="{{sign_in_url_}}">Sign in to rate this resto...</a>
        {% endif %}
      </div>
    </div><!--/.view-->
  
  {% endif %}
  
  <!-- edit _____________________________________________________________________________________-->
  
  {% if user_ and not rating %}
  
    <div class="edit hidden">
    
      <form id="rate_resto_form" class="form" action="." method="POST"
            onsubmit="return submitAjaxForm('#ratings', '#rate_resto_form');">
        <input type="hidden" name="ajax_box" value="ratings"/>
        <div>
          <table>
            <tbody>
              <tr>
                <th>Cuisine:</th>
                <td><input style="width: 60px;" type="text" name="cuisine" value="3"/></td>
              </tr>
              <tr>
                <th>Economy:</th>
                <td><input style="width: 60px;" type="text" name="economy" value="3"/></td>
              </tr>
              <tr>
                <th>Service:</th>
                <td><input style="width: 60px;" type="text" name="service" value="3"/></td>
              </tr>
            </tbody>
          </table>
        </div>
        <div>
          <input class="button" type="submit" value="Rate"/>
          <input class="button" type="button" onclick="toggleBox('#ratings');" value="Cancel"/>
          <span class="ajax_indicator hidden">
            <img src="{{static_}}/images/ajax_indicator.gif" alt="AJAX Indicator"/>
          </span>
        </div>
      </form>
    
    </div><!--/.edit-->
  
  {% endif %}{# user_ and not rating #}
  
</div><!--/#ratings-->


